﻿using AntdUI;
using ImportPlcPointPosition.Models.Table;
using ImportPlcPointPosition.Models.ViewModels;
using ImportPlcPointPosition.Utils;
using Newtonsoft.Json.Linq;
using SqlSugar.Extensions;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ZR.Model.Models.ProductionControl;

namespace ImportPlcPointPosition.Forms
{
    public partial class ImportProcessDataForm : BaseForm
    {
        public ImportProcessDataForm()
        {
            InitializeComponent();
          
        }

        public List<(string desc, string name,string dataType)> Values { get; set; }


        private void BlockDbEditForm_Load(object sender, EventArgs e)
        {
          
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            try {
                Values = new List<(string desc, string name, string dataType)>();

                //txtRemark.Text.Trim().Split("\r\n")[0].Trim().Split("\t").Where(o => !string.IsNullOrEmpty(o));

                foreach (var item in txtRemark.Text.Trim().Split("\r\n")) {
                    var arr = item.Trim().Split("\t").Where(o => !string.IsNullOrEmpty(o)).ToArray();
                    if (arr.Length < 3) {
                        AntdUI.Message.error(App.MainLayout, "请按照格式填写数据：描述\t符号\t数据类型");
                        return;
                    }
                    Values.Add((arr[0].Trim(), arr[1].Trim(), arr[2].Trim()));
                }

                if (Values.Any(o => string.IsNullOrEmpty(o.name) || string.IsNullOrEmpty(o.dataType) || string.IsNullOrEmpty(o.desc))) {
                    AntdUI.Message.error(App.MainLayout, "描述、符号和数据类型不能为空");
                    return;
                }

                DialogResult = DialogResult.OK;

            } catch (Exception ex) {
                AntdUI.Message.error(App.MainLayout,"解析异常！" + ex.Message);
                //throw;
            }
        }


    }
}
